#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 205;
const int maxv = 200050;
int f[maxv],v[maxn],w[maxn],m[maxn],n,mv;

int main(){
	cin>>n>>mv;
	for(int i=1;i<=n;i++){
		cin>>v[i]>>w[i]>>m[i];
		if(m[i] == -1 || m[i] > mv/v[i])	m[i] = mv/v[i];
	}
	
	for(int i =1;i<=n;i++){
		int k=1;
		while(k<=m[i]){
			for(int j=mv;j>=k*v[i];j--)	f[j]=max(f[j],f[j-k*v[i]]+k*w[i]);
			m[i] = m[i]-k;
			k=k*2;
		}
		for(int j=mv;j>=m[i]*v[i];j--)	f[j]=max(f[j],f[j-m[i]*v[i]]+w[i]*m[i]);
	}

	
	cout<<f[mv]<<endl;
	return 0;
}